<?php
require_once '../config.php';
require_once '../dao/dao_db.php';
require_once '../dao/dao_qa.php';
session_start();
session_cache_limiter('private');
if($_POST['questiontype']!=''){
	$questiontype=$_POST['questiontype'];
}
if(trim($_POST['questiontitle'])!=''){
	$questiontitle=$_POST['questiontitle'];
}
if(trim($_POST['questioncontent'])!=''){
	$questioncontent=$_POST['questioncontent'];
}
if(isset($_GET['id'])){
	$titleid=$_GET['id'];
}
if(isset($_SESSION['userid'])&&trim($questioncontent)!=''){
	if($_SESSION['level']==TEACHER||$_SESSION['level']==STUDENT){
		$ipaddress=$_SERVER['REMOTE_ADDR'];
		$result=save_question($questiontitle,$questioncontent,$_SESSION['userid'],$questiontype,$ipaddress);
		mysql_close();
		header("LOCATION:../list_question.php");
	}
}elseif (isset($_SESSION['userid'])&&$titleid!=''){
	if($_SESSION['level']==ADMINISTRATOR){
		$result=check_deleting_questions($titleid,$_SESSION['userid']);
		if(mysql_num_rows($result)!=0){
			del_questions($titleid);
			mysql_close();
		}else{
			header("location:../error.php?errcode=1");
		}
		header("location:../list_question.php");
	}
}else{
	header("location:../error.php?errcode=1");
}
?>